<?php

use IDock\Insurance\HBIC\Bean\BASEPART;
use IDock\Insurance\HBIC\Bean\CAR;
use IDock\Insurance\HBIC\Bean\CARSHIPTAX;
use IDock\Insurance\HBIC\Bean\CHANGEBASEPART;
use IDock\Insurance\HBIC\Bean\DERATE;
use IDock\Insurance\HBIC\Bean\DEVICE;
use IDock\Insurance\HBIC\Bean\ENGAGE;
use IDock\Insurance\HBIC\Bean\INSURED;
use IDock\Insurance\HBIC\Bean\KIND;
use IDock\Insurance\HBIC\Bean\PAID;
use IDock\Insurance\HBIC\Bean\APPLICANT;
use IDock\Insurance\HBIC\Bean\PERSONNEL;
use IDock\Insurance\HBIC\HBICConstruct;

require_once 'vendor/autoload.php';

$HBConfig = [
    'gateway' => 'http://58.17.45.9:9002/hbins/CNinsureToHB',
    'logsDir' => './HENGBANGLogs',
    'timeout' => '60',
    'userCode' => '3600000381',
    'comCode' => '0101282001',
    'proxy' => '118.123.247.195:45131',
];


$IDock = new HBICConstruct($HBConfig);

global $testResponse;

//$testResponse = '';

try {

    if (1) {
        //保费计算
        $basePart = new BASEPART();
        $basePart->setRISKTYPE('2');
        $basePart->setSTARTDATEBI('2023-08-05 00:00:00');//商业险起保日期
        $basePart->setSTARTDATECI('2023-08-05 00:00:00');//交强险起保日期
        $basePart->setENDDATEBI('2024-08-04 23:59:59');//商业险终保日期
        $basePart->setENDDATECI('2024-08-04 23:59:59');//交强险终保日期
        $basePart->setINPUTSYSCODE('0401');//业务渠道代码
        $basePart->setAREACODE('360000');//投保地区
        $basePart->setINSUREDNAME('樊鑫');//被保人
        $basePart->setCOMPANYCODE('0106010101');//业务归属机构
        $basePart->setAGREEMENTNO('010601010100200010');//中介协议号
        $basePart->setINTERMEDIARYCODE('075000000914');//中介人代码
        $basePart->setSALESMANCODE('3600001010');//销售员代码
        $basePart->setBUSINESSMODE('2');//业务方式
        $basePart->setBUSINESSSOURCE('0100');//业务来源
        $basePart->setCHANNELTIP('04010100');//渠道小类
        $basePart->setCHANNELDETAILCODE('0401');//渠道细类
        $basePart->setOPERATORCODE('PSC0000008');//操作员代码
        $basePart->setEFFECTFLAG('0');//即时起保标志
        $basePart->setEPOLICYFLAG('Y');//电子投保标识
        $basePart->setCLAUSETYPE('2');//
        $basePart->setOUTOFWARRANTYTYPE('Y');
        $basePart->setOUTSYNCTYPE('0');

        //车辆信息
        $car = new CAR();
        $car->setENROLLDATE('2015-09-07 00:00:00');//初登日期
        $car->setLICENSENO('川A0B86E');
        $car->setENGINENO('FW142288');
        $car->setFRAMENO('LJDTAA231F0063025');
        $car->setBRANDNAME('三菱CFA2031G轻型越野车');//厂牌名称
        $car->setMODELCODE('SLAAHD0020');//车型编码
        $car->setCARKINDCODE('100');//车辆种类
        $car->setUSENATURECODE('02');//使用性质代码，非营业不传
        $car->setATTACHNATURE('01');//所属性质
        $car->setCARUSETYPE('01');//车辆用途
        $car->setNEGOTIATIONVALUE('125888.0');//协商价值
        $car->setCAROWNER('樊鑫');
        $car->setCREDENTIALNO('510182199010295828');//车主证件号码
        $car->setCREDENTIALTYPE('01');//车主证件类型 身份证
        $car->setLICENSEKINDCODE('02');//号牌种类代码
        $car->setVEHICLETYPE('K33');//行驶证车辆类型代码
        $car->setJGVEHICLETYPE('K33');//默认K33
        $car->setCHGOWNERFLAG('0');//是否是过户车
        $car->setSEATCOUNT('5');//座位
        $car->setPURCHASEPRICE('281000.0');//新车购置价
        $car->setEXHAUSTSCALE('2972.0');//排量
        $car->setCOMPLETEKERBMASS('2120.0');//整车质量
        $car->setCIMODELCODE('BCFHPKUC0002');//
        $car->setPRINTBRANDNAME('三菱CFA2031G轻型越野车');
        $car->setINSUREDTYPECODE('1');//车主类型（个人：1；团体：2）
        $car->setENERGYTYPE('0');

        //险别信息
        $kind = new KIND();
        $kind->setITEMKINDNO('1');//序号，从1递增
        $kind->setKINDCODE('BZ');//险别代码
        $kind->setMODECODE('');
        $kind->setQUANTITY('');
        $kind->setMODEL('');//是否投保不计免赔率： 0-否，1-是
        $kind->setUNITAMOUNT('');
        $kind->setAMOUNT('200000');//保险金额/赔偿限额
        $kind->setRATE('');
        $kind->setVALUE('');
        $kind->setDEDUCTIBLEFRANCHISE('');
        $kind->setSERVICETIMES('');

        $kind2 = new KIND();
        $kind2->setITEMKINDNO('2');//序号，从1递增
        $kind2->setKINDCODE('101');//车损险
        $kind2->setMODECODE('');
        $kind2->setQUANTITY('');
        $kind2->setMODEL('0');//是否投保不计免赔率： 0-否，1-是
        $kind2->setUNITAMOUNT('');
        $kind2->setAMOUNT('125888');//保险金额/赔偿限额
        $kind2->setRATE('');
        $kind2->setVALUE('');
        $kind2->setDEDUCTIBLEFRANCHISE('');
        $kind2->setSERVICETIMES('');

        $kind3 = new KIND();
        $kind3->setITEMKINDNO('3');//序号，从1递增
        $kind3->setKINDCODE('102');//商业三责险
        $kind3->setMODECODE('');
        $kind3->setQUANTITY('');
        $kind3->setMODEL('0');//是否投保不计免赔率： 0-否，1-是
        $kind3->setUNITAMOUNT('');
        $kind3->setAMOUNT('1000000');//保险金额/赔偿限额
        $kind3->setRATE('');
        $kind3->setVALUE('');
        $kind3->setDEDUCTIBLEFRANCHISE('');
        $kind3->setSERVICETIMES('');

        $kind4 = new KIND();
        $kind4->setITEMKINDNO('4');//序号，从1递增
        $kind4->setKINDCODE('103');//车上人员责任险（司机）
        $kind4->setMODECODE('');
        $kind4->setQUANTITY('1');
        $kind4->setMODEL('0');//是否投保不计免赔率： 0-否，1-是
        $kind4->setUNITAMOUNT('50000');
        $kind4->setAMOUNT('50000');//保险金额/赔偿限额
        $kind4->setRATE('');
        $kind4->setVALUE('');
        $kind4->setDEDUCTIBLEFRANCHISE('');
        $kind4->setSERVICETIMES('');

        $kind5 = new KIND();
        $kind5->setITEMKINDNO('5');//序号，从1递增
        $kind5->setKINDCODE('104');//车上人员责任险（乘客）
        $kind5->setMODECODE('');
        $kind5->setQUANTITY('4');
        $kind5->setMODEL('0');//是否投保不计免赔率： 0-否，1-是
        $kind5->setUNITAMOUNT('10000');
        $kind5->setAMOUNT('40000');//保险金额/赔偿限额
        $kind5->setRATE('');
        $kind5->setVALUE('');
        $kind5->setDEDUCTIBLEFRANCHISE('');
        $kind5->setSERVICETIMES('');

        //车船税信息
        $carShip = new CARSHIPTAX();
        $carShip->setTAXRELIF('02');//纳税类型代码
        $carShip->setTAXNAME('樊鑫');//纳税人姓名
        $carShip->setTAXCERTITYPE('01');//纳税人证件类型
        $carShip->setTOTALTONCOUNT('1.2');
        $carShip->setTAXPAYERIDENTIFIER('510182199010295828');//纳税人识别码
        $carShip->setTAXIDENTIFYNUMBER('510182199010295828');//纳税人证件号码
        $carShip->setFUELTYPE('0');

        $paid = new PAID();//完税信息
        $paid->setTAXDEPARTMENT('');
        $paid->setTAXDOCUMENTNUMBER('');
        $paid->setPAIDAREACODE('');
        $paid->setPAIDTAXDOCUMENTDATE('');
        $carShip->setPAID($paid);

        $deRate = new DERATE();//减免税信息
        $deRate->setDEDUCATIONDUECODE('');
        $deRate->setDEDUCATIONDUETYPE('');
        $deRate->setDEDUCATIONDUEPROPOTION('');
        $deRate->setDEDUCATION('');
        $deRate->setDEDUCATIONDOCUMENTNUMBER('');
        $deRate->setTAXDEPARTMENT('');
        $carShip->setDERATE($deRate);

        //新增设备信息
        $device = new DEVICE();
        $device->setDEVICENAME('');//设备名称
        $device->setSERIALNO('');//从1开始
        $device->setQUANTITY('');//数量
        $device->setPURCHASEPRICE('');//购置价
        $device->setBUYDATE('');//购置时间

        $person = new PERSONNEL();
        $person->setAPPNAME('樊鑫');
        $person->setAPPCUSTOMERTYPE('00');
        $person->setINSUREDNAME('樊鑫');
        $person->setVIPIND('0');
        $person->setINSUREDCUSTOMERTYPE('00');


        $response = $IDock->InsuranceOrderQuery($basePart, $car, [$kind, $kind2, $kind3, $kind4, $kind5], $carShip, $person);
        var_dump($response->getCode());
        var_dump($response->isSuccess());
        var_dump($response->getError());
        var_dump($response->getData());
    }

    if (0) {
        //获取车辆实际价格
        $enrollDate = '2015-09-07 00:00:00';//初登日期
        $purchasePrice = '281000';//新车购置价格
        $carKindCode = '100';//车辆种类
        $useNatureCode = '02';//使用性质代码
        $energyType = '0';//能源类型
        $seatCount = '5';//座位数
        $tonCount = '';//核定载质量
        $carUseType = '01';//车辆用途
        $riskType = '0808';//险种代码
        $startDate = '2023-06-05 00:00:00';//起保日期
        $response = $IDock->GetActualValue($enrollDate, $purchasePrice, $carKindCode, $useNatureCode, $energyType, $seatCount, $tonCount, $carUseType, $riskType, $startDate);
        var_dump($response->getCode());
        var_dump($response->isSuccess());
        var_dump($response->getError());
        var_dump($response->getBody());


    }

    if (0) {
        //投保
        $basePart = new CHANGEBASEPART();
        $basePart->setQUOTATIONNO('02060101000020230000717');
        $basePart->setPACKAGECODE('P14');
        $basePart->setRISKTYPE('2');//
        $basePart->setINPUTSYSCODE('A5');

        $insured = new INSURED();
        $insured->setINSUREDFLAG('1');//被保人
        $insured->setCOUNTRYCODE('CN');
        $insured->setIDENTIFYNUMBER('510182199010295828');//证件号码
        $insured->setPOSTCODE('610000');//邮政编码
        $insured->setINSUREDADRESS('四川成都');//地址
        $insured->setINSUREDNAME('樊鑫');//被保人姓名
        $insured->setMOBILE('15690728909');
        $insured->setEMAIL('');
        $insured->setOCCUPATIONCODE('60');
        $insured->setINSUREDTYPE('1');
        $insured->setIDENTIFYTYPE('01');
        $insured->setIDENTIFYNUMBERSTART('2015-12-30');
        $insured->setIDENTIFYNUMBEREND('2035-12-30');
        $insured->setCUSTOMERTYPE('00');
        $insured->setSTARLEVEL('0');


        $applicant = new APPLICANT();
        $applicant->setINSUREDFLAG('2');//投保人
        $applicant->setCOUNTRYCODE('CN');
        $applicant->setIDENTIFYNUMBER('510182199010295828');//证件号码
        $applicant->setPOSTCODE('610000');//邮政编码
        $applicant->setINSUREDADRESS('四川成都');//地址
        $applicant->setINSUREDNAME('樊鑫');//被保人姓名
        $applicant->setMOBILE('15690728909');
        $applicant->setEMAIL('');
        $applicant->setOCCUPATIONCODE('60');
        $applicant->setINSUREDTYPE('1');
        $applicant->setIDENTIFYTYPE('01');
        $applicant->setIDENTIFYNUMBERSTART('2015-12-30');
        $applicant->setIDENTIFYNUMBEREND('2035-12-30');
        $applicant->setCUSTOMERTYPE('00');
        $applicant->setSTARLEVEL('0');

        //特约
        $engage = new ENGAGE();
        $engage->setCLAUSECODE('0808');
        $engage->setCLAUSECNAME('第一现场报案');
        $engage->setCLAUSECONTEXT('为更好地保障您的权益,请您在发生保险事故后保留出险第一现场,并立即致电24小时服务电话:956079。');
        $engage->setRISKCODE('T001_1');

        $engage1 = new ENGAGE();
        $engage1->setCLAUSECODE('0808');
        $engage1->setCLAUSECNAME('交强险投保提示');
        $engage1->setCLAUSECONTEXT('保险人已告知投保人，本保险为商业保险，应按规定另行办理交强险。保险车辆未投保交强险或交强险合同已经失效的，对于交强险责任限额以内的损失和费用，本公司不负责赔偿。');
        $engage1->setRISKCODE('T002_1');


        $response = $IDock->InsuranceCheck($basePart, [$insured, $applicant], [$engage, $engage1]);
        var_dump($response->getCode());
        var_dump($response->isSuccess());
        var_dump($response->getError());
        var_dump($response->getData());

    }

    if (0) {
        //精准车型查询
        $VIN = '23423414134143214';//车辆识别码
        $firstRegisterDate = '2017-11-22';//注册日期
        $licenseNo = '赣DFDF10';//车牌号码
        $engineNumber = '1243124312343124';//发动机编号
        $response = $IDock->CarModelQuery($VIN, $firstRegisterDate, $licenseNo, $engineNumber);
        var_dump($response->getCode());
        var_dump($response->isSuccess());
        var_dump($response->getError());
        var_dump($response->getData());

    }

    if (0) {
        //投保单查询
        $proposalNo = '';//投保单号
        $RISKTYPE = '3';//默认3
        $queryType = '3';//1-保单查询，0为基础投保单号查询，2.其他类型查询,3.询价单查询
        $LicenseNo = '';//车牌号
        $VinNo = '';//车架号
        $quotationNo = '02060101000020230000717';//询价单号
        $SplitFlag = '';//交商不同步标志
        $response = $IDock->OrderCheckQuery($proposalNo, $RISKTYPE, $queryType, $LicenseNo, $VinNo, $quotationNo, $SplitFlag);
        var_dump($response->getCode());
        var_dump($response->isSuccess());
        var_dump($response->getError());
        var_dump($response->getData());
    }

    if (0) {
        //保单查询
        $policyNo = '';
        $vinNo = '';
        $licenseNo = '赣DFDF10';
        $uwYear = '';
        $response = $IDock->PolicyOrderQuery($policyNo, $vinNo, $licenseNo, $uwYear);
        var_dump($response->getCode());
        var_dump($response->isSuccess());
        var_dump($response->getError());
        var_dump($response->getData());
    }

    if (0) {
        //四川实名认证短信验证码获取与保存
        $verificationType = '1';//1:获取 2:提交
        $businessNo = '02060101000020230000717';//投保单号
        $riskCode = '0801';//险种信息
        $businessType = '1';//1.保单; 2.批单
        $verificationCode = '';//验证码，提交时必传
        $response = $IDock->SmsCodeVerifyAndSubmit($verificationType, $businessNo, $riskCode, $businessType, $verificationCode);
        var_dump($response->getCode());
        var_dump($response->isSuccess());
        var_dump($response->getError());
        var_dump($response->getData());
    }

    if (0) {
        //四川交管车辆查询
        $licenseKindCode = '02';//车辆号牌种类
        $licenseNo = '川B779PE';//车辆号牌号码
        $Vin = '021847';//车架号后六位
        $response = $IDock->SichuanTrafficVehicleRequest($licenseKindCode, $licenseNo, $Vin);
        var_dump($response->getCode());
        var_dump($response->isSuccess());
        var_dump($response->getError());
        var_dump($response->getData());
    }

    if(1){
        //保单撤回接口
    }

} catch (Exception $e) {
    var_dump($e->getMessage());
}